<template>
  <view>
    <view class="list-box">
      <view v-for="(item,d) in dataList" :key="d" @click="handlerList(item.goods_id)">
        <my-goodsList :item="item" />
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
    
        querobj1: {
          query: "",
          cid: "",
          pagenum: 1,
          pagesize: 10
        },
        totle: 0,
        dataList: [],
        isLoading: false
      };
    },
    onLoad(options) {
    this.querobj1.cid = options.cid || ""
      this.querobj1.query = options.query || ""
     this.getDataLIst()
    },
    onPullDownRefresh() {
      this.querobj1.pagenum = 1
        this.querobj1.pagesize = 10
        this.totle = 0
        this.dataList = []
      this.getDataLIst(() => {
        uni.stopPullDownRefresh()
      })
    },
    onReachBottom() { 
      if (this.isLoading) return
      this.querobj1.pagenum += 1
      // if (this.querobj1.pagenum * this.querobj1.pagesize >= this.totle) return uni.$showmag("数据获取完毕", 1000, "none")
      this.querobj1.pagenum * this.querobj1.pagesize < this.totle ?  this.getDataLIst() : uni.$showmag("数据获取完毕", 1000, "none")
      // this.getDataLIst()

    },

    methods: {
      handlerList(id) {

        uni.navigateTo({
          url: `/subpkg/goods_detail/goods_detail?goods_id=${id}`
        })
      },
      async getDataLIst(cd) {
         console.log(this.querobj1.pagenum)
        this.isLoading = true
       
        const {data: res} = await uni.$http.get('/api/public/v1/goods/search',{...this.querobj1})
       
        try{
          // if (res.meta.status !== 200) return uni.$showmag("数据请求失败", 1000, "none")
            this.dataList = [...this.dataList, ...res.message.goods]
            this.dataList = res.message.goods
            this.totle = res.message.total
        }catch(e){e=>{
           console.log(e)
        }}
        
        
          // if (res.meta.status !== 200) return uni.$showmag("数据请求失败", 1000, "none")
          //   this.dataList = [...this.dataList, ...res.message.goods]
          //   this.dataList = res.message.goods
          //   this.totle = res.message.total
  
          
       this.isLoading = false
        // uni.$showmag('数据请求成功',2000,"none")
        cd && cd()

      },

    }
  }
</script>


<style lang="scss">
  .list-box {
    .list-item {
      height: 150px;
      display: flex;
      margin: 0px 10px;
      box-shadow: 10px 10px 5px #E5E5E5;

      .list-left {
        width: 140px;
        height: 140px;
        padding: 10px;

        .leftImage {
          width: 100%;
          height: 100%;
        }
      }

      .list-right {
        display: flex;
        flex-wrap: wrap;
        flex-direction: column;
        justify-content: space-between;

        .list-text {
          font-size: 13px;
          padding: 10px 0;
        }

        .list-bottom {
          font-size: 18px;
          font-weight: bold;
          padding: 10px 0;
          color: red;
        }
      }
    }
  }
</style>
